package com.yihuu.common;

/**
 * Created by yuhui on 2017/7/11.
 */
public class Result<T> {

    public static final  Integer SUCESS=0;
    public static final  Integer ERROR=1;

    private Integer code;

    private  String msg;

    private T data;

    public Integer getCode() {
        return code;
    }

    public Boolean isSuccess(){
        return this.getCode()==SUCESS;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private Result(){}

    private Result(Integer code,String msg){
        this.code=code;
        this.msg=msg;
    }
    private Result(Integer code,String msg,T data){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }

    public static Result createBySuccess(String msg){
        return new Result(SUCESS,msg);
    }
    public static <T> Result<T> createBySuccess(String msg,T data){
        return new Result(SUCESS,msg,data);
    }

    public static Result createByError(String msg){
        return new Result(ERROR,msg);
    }
}
